package com.guli.gulimall.gulimallcoupon.controller;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;
import com.guli.gulimall.gulimallcoupon.entity.CouponEntity;
import com.guli.gulimall.gulimallcoupon.service.CouponService;
import com.guli.common.utils.PageUtils;
import com.guli.common.utils.R;



/**
 * 优惠券信息
 *
 * @author zouzhi
 * @email 1245268075@qq.com
 * @date 2022-04-03 14:35:34
 */
@RestController
@RequestMapping("gulimallcoupon/coupon")
@Api(value ="CouponController接口",tags = "优惠卷信息接口")
@RefreshScope
public class CouponController {
    @Autowired
    private CouponService couponService;
    @Value("${user.name:zz123}")
    private String name;
    @Value("${user.age:12}")
    private int age;
    @GetMapping("/menber/list")
    @ApiOperation(value = "会员服务查询")
    public  R menberCoupons(){
        CouponEntity couponEntity = new CouponEntity();

        couponEntity.setCouponName("满一百减10"+name+age);
        System.out.println("1");
        return  R.ok().put("coupons", Arrays.asList(couponEntity));

    }
    /**
     * 列表
     */
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = couponService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		CouponEntity coupon = couponService.getById(id);

        return R.ok().put("coupon", coupon);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody CouponEntity coupon){
		couponService.save(coupon);

        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    public R update(@RequestBody CouponEntity coupon){
		couponService.updateById(coupon);

        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		couponService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
